﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace WebApmDemo1.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestAController : Controller
    {
        private readonly IHttpClientFactory _httpClient;
        public TestAController(IHttpClientFactory httpClient)
        {
            this._httpClient = httpClient;
        }

        [HttpGet, HttpPost]
        public async Task<IActionResult> Index()
        {
            //demo2的请求地址
            var url = "http://localhost:44342/api/test";
            var client = _httpClient.CreateClient();
            var result = await client.GetStringAsync(url);
            return Content(result);
        }


        [HttpGet, HttpPost]
        [Route("TestOne")]
        public IActionResult TestOne()
        {
            Thread.Sleep(5000);
            return Content("我是TestOne");
        }


        [HttpGet, HttpPost]
        [Route("TestTwo")]
        public IActionResult TestTwo()
        {
            throw new Exception("TestTwo报错了 ");
            return Content("我是TestTwo");
        }
    }
}
